<?php
if(!defined('IN_DISCUZ')){
	exit('Access Denied');
}

class mobileplugin_qiwu_ror_html_img
{
    
}

class mobileplugin_qiwu_ror_html_img_forum extends mobileplugin_qiwu_ror_html_img
{
    var $plugin_name = 'qiwu_ror_html_img';
    
    function viewthread_bottom_mobile_output()
    {
        global $postlist;

        $html = '';

        $rule = '/<img.*?src="(.*?)".*?>/is';
        foreach($postlist as $key => $post){
            if(strpos($post['message'], '<img') !== FALSE){
                $postlist[$key]['message'] = preg_replace_callback($rule, $this->plugin_name.'_src_wap', $post['message']);
            }
        }
        
        return $html;
    }
}

function qiwu_ror_html_img_src_wap($matches)
{
    global $_G;

    $config = $_G['cache']['plugin']['qiwu_ror_html_img'];
    
    if(strpos($matches[1], 'forum.php') === 0){
        $url_temp = $config['img_local_host'].$matches[1];
        $url_temp .= $config['img_postfix'];
        return str_replace($matches[1], $url_temp, $matches[0]);
    }else if(strpos($matches[1], './data/') === 0){
        $url_temp = $config['img_local_host'].$matches[1];
        $url_temp .= $config['img_postfix'];
        return str_replace($matches[1], $url_temp, $matches[0]);
    }else if(strpos($matches[1], 'data/') !== FALSE){
        $url_temp = $config['img_local_host'].$matches[1];
        $url_temp .= $config['img_postfix'];
        return str_replace($matches[1], $url_temp, $matches[0]);
    }else if($config['img_from_host'] && $config['img_to_host'] && strpos($matches[1], $config['img_from_host']) !== FALSE){
        $url_temp = str_replace($config['img_from_host'], $config['img_to_host'], $matches[1]);
        $url_temp .= $config['img_postfix'];
        return str_replace($matches[1], $url_temp, $matches[0]);
    }
    
    return $matches[0];
}